<template>
  <div>
    <el-table v-bind="$attrs"
              :max-height="maxHeightNow"
              v-on="$listeners">
      <template v-for="(item, index) in columns">
        <!-- 自定义插槽 -->
        <el-table-column v-if="item.slotName"
                         v-bind="item"
                         :key="index">
          <template slot-scope="scope">
            <slot :name="item.slotName"
                  :scope="scope"></slot>
          </template>
        </el-table-column>
        <!-- 原生插槽 -->
        <el-table-column v-else
                         v-bind="item"
                         :key="index" :selectable="selectable">
						  <!-- :selectable="selectable" -->
        </el-table-column>
      </template>
    </el-table>
    <e-pagination v-if="pageShow"
                  :total="total"
                  :current-page.sync="currentPage"
                  v-bind="pageOption"
                  @size-change="sizeChange"
                  @current-change="currentChange"
                  @prev-click="prevClick"
                  @next-click="nextClick"></e-pagination>
  </div>

</template>

<script>
import Epagination from '@/components/e-pagination'
export default {
  name: 'Etable',
  components: {
    'e-pagination': Epagination
  },
  props: {
    columns: {
      type: Array,
      default () {
        return []
      }
    },
    maxHeight: {
      type: Number,
      default: 0
    },
    // 分页配置
    pageShow: {
      type: Boolean,
      default: true
    },
    total: {
      type: Number,
      default: 0
    },
    current: {
      type: Number,
      default: 1
    },
    pageOption: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      currentPage: 0
    }
  },
  watch: {
    current (newVal) {
      this.currentPage = newVal
    },
    currentPage (newVal) {
      this.$emit('update:current', newVal)
    }
  },
  computed: {
    maxHeightNow () {
      if (!this.maxHeight) {
        const height = window.innerHeight
        return height - (this.pageShow ? 290 : 242)
      }
      return this.maxHeight
    }
  },
  methods: {
	selectable(row){
		console.log(row.has)
		if(row.has == 1){
			return false
		}else if(row.has == 0){
			return true
		}else{
			return true
		}
	},
    sizeChange (pageSize) {
      this.$emit('page-size-change', pageSize)
    },
    currentChange (current) {
      this.$emit('page-current-change', current)
    },
    prevClick (current) {
      this.$emit('page-prev-click', current)
    },
    nextClick (current) {
      this.$emit('page-next-click', current)
    }
  },
  created () { },
  mounted () { }
}
</script>
<style lang="scss" scoped>
</style>
